package com.w2cx.selenium.operate;

import com.w2cx.selenium.base.DriverBase;
import com.w2cx.selenium.page.SensitiveWordsManagePage;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.List;

public class SensitiveWordsManageOperate {

    DriverBase driver;
    SensitiveWordsManagePage swmp;
    public SensitiveWordsManageOperate(DriverBase driver){
        this.driver = driver;
        swmp = new SensitiveWordsManagePage(driver);
    }


    //点击“基础数据管理”菜单
    public void clickBaseDataManageMenu(){
        swmp.click(swmp.getBaseDataManageMenu());
    }

    //点击“敏感词管理”菜单
    public void clickSensiWordManageMenu(){
        swmp.click(swmp.getSensiWordManageMenu());

    }


    //点击添加敏感词按钮
    public void clickAddSensiWordBtn(){
        swmp.click(swmp.getAddSensitiveWordBtn());
    }

    //输入敏感词名称
    public void inputSensiWordName(String name){
        swmp.sendKeys(swmp.getSensiWorkInput(),name);
    }

    //点击确定按钮
    public void clickAddConfirmBtn(){
        swmp.click(swmp.getAddConfirmBtn());
    }

    //获取元素列表
    public List<WebElement> getSensiWordList(){
        return swmp.getSensiWordLevel0List();
    }


    //点击“删除”按钮
    public void clickDelSensiWordBtn(String alreadyAddSensiWordName){

        ArrayList<WebElement> list = (ArrayList<WebElement>) swmp.getSensiWordLevel0List();
        for (int i=0;i<list.size();i++){
            WebElement element = list.get(i);
            if(element.getText().contains(alreadyAddSensiWordName)){
                swmp.click(swmp.getSensiWordDelBtn(element));
            }

        }


    }

    //点击“确定”按钮
    public void clickDelSensiConfirmBtn(){
        swmp.click(swmp.getSensiDelConfirmBtn());
    }



}
